﻿using FAMailUtils;
using FAMailUtils.Data.DAO;
using FAMailUtils.Data.DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineBusinesses.Areas.CustomerAdmin.MailBox
{
    public partial class ChooseGroupsMails : System.Web.UI.Page
    {
        AccountDAO dao = new AccountDAO();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public List<AccountDTO> Search(string name, string email)
        {
            List<AccountDTO> result = new List<AccountDTO>();

            try
            {
                DataTable tb = dao.Search(email, name);
                AccountDTO item = new AccountDTO();
                foreach (DataRow dr in tb.Rows)
                {
                    item = new AccountDTO();
                    item.AccountID = Convert.ToInt32(dr["AccountID"] + "");
                    item.AccountName = dr["AccountName"] + "";
                    item.Email = dr["Email"] + "";
                    item.Phone = dr["Phone"] + "";
                    item.Function = dr["Function"] + "";
                    item.Address = dr["Address"] + "";
                    result.Add(item);
                }
            }
            catch (Exception ex)
            {
                Common.logs(Request.RawUrl + "-" + Common.GetCurrentMethod(), ex, Common.logType.error);
            }
            return result;
        }
    }
}